package 
{
	import vk.APIConnection;	
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
	public class KNVKAPI extends Object
	{
	    public var InDebug: Boolean = false;
		private var VKConnection: APIConnection = null;
		private var flashVars: Object = null;
		
		private function callMethod(...params):void
		{
			try
			{
				if (VKConnection != null)
					VKConnection.callMethod(params);
			}
			catch (e: Error)
			{
				new TModalMessage("Ошибка выполнения метода сервера");
			}			
		}
		
		private function api(method: String, params: Object, onComplete:Function = null):void 
		{
			if (InDebug)
			  params.test_mode = 1;
			GameInfo.AddRequest();
			var L: TRequestListener = new TRequestListener(GameInfo, onComplete);
			VKConnection.api(method, params, L.OnComplete, L.onFail);
		}
		
		public function APIExecute(Code: String, OnComplite: Function = null): void
		{
			var Params: Object = new Object();
			Params.code = Code;
			api('execute', Params, OnComplite);
		}
		
		public function APIPutVariable(Key: int, Value: String, UserID: int, OnComplite: Function = null): void
		{
			var Params: Object = new Object();
			Params.key = Key;
			Params.value = Value;
			Params.user_id = UserID;
			api("putVariable", Params, OnComplite);
		}
		
		//todo: remove
		private var GameInfo: TGameInfo = null;
		
		public function KNVKAPI(flashvars: Object, aGameInfo: TGameInfo) 
		{
			GameInfo = aGameInfo;
			VKConnection = new APIConnection(flashvars);
		}

	}
	
}